package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.Date;

import com.corpcredit.Constants;
import com.corpcredit.model.GlryFddbr;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class GlryFddbrForm extends BasePage implements Serializable {
    private GenericManager<GlryFddbr, Long> glryFddbrManager;
    private GlryFddbr glryFddbr = new GlryFddbr();
    private Long id;

    public void setGlryFddbrManager(GenericManager<GlryFddbr, Long> glryFddbrManager) {
        this.glryFddbrManager = glryFddbrManager;
    }

    public GlryFddbr getGlryFddbr() {
        return glryFddbr;
    }

    public void setGlryFddbr(GlryFddbr glryFddbr) {
        this.glryFddbr = glryFddbr;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        glryFddbrManager.remove(glryFddbr.getId());
        addMessage("glryFddbr.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            glryFddbr = glryFddbrManager.get(id);
        } else {
            glryFddbr = new GlryFddbr();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (glryFddbr.getId() == null || glryFddbr.getId() == 0);
        
        //glryFddbr.setJbqk(jbqk);
        glryFddbr.setUsername(getRequest().getRemoteUser());
        glryFddbr.setOptdate(new Date());
        glryFddbr.setOperation(isNew?Constants.OPERATION_ADD:Constants.OPERATION_UPDATE);
        

        
        glryFddbrManager.save(glryFddbr);

        String key = (isNew) ? "glryFddbr.added" : "glryFddbr.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
        	  this.id=this.glryFddbr.getId();
              return edit();

        }
    }
} 